package com.ruoyi.common.apiResult;

import com.fasterxml.jackson.annotation.JsonValue;

import java.io.Serializable;

public class Result implements Serializable {


	private static final long serialVersionUID = 6230939589190169253L;

	public enum Code{
		SUCCESS(0, "成功"),
		SYSTEMERROR(1001, "系统出了点小bug，请联系开发人员"),
		REQUESTERROR(1002, "请求错误"),
		FAILED(1003, "失败"),
		SIGNERROR(1004, "签名错误"),
		PARAMERROR(1005, "参数错误"),
		ROLEBAN(1006,"权限不足"),
		UNIQUECONSTRAINTERROR(1007, "数据唯一属性冲突"),
		AUTHERROR(1008, "数据唯一属性冲突"),
		NEEDLOGIN(1009,"需要登录");
		private int code;
		private String errorMessage;



		private Code(int code, String errorMessage) {
			this.code = code;
			this.errorMessage = errorMessage;
		}

		@JsonValue
		public int getCode() {
			return code;
		}

		public void setCode(int code) {
			this.code = code;
		}

		public String getErrorMessage() {
			return errorMessage;
		}

		public void setErrorMessage(String errorMessage) {
			this.errorMessage = errorMessage;
		}
	}

	private Code code;
	private String message;
	private Object data;
	private long count;
	public void setMessage(String message) {
		this.message = message;
	}
	public long getCount() {
		return count;
	}



	public void setCount(long count) {
		this.count = count;
	}
	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public String getMessage() {
		return message;
	}

	public Code getCode() {
		return code;
	}

	public void setCode(Code code) {
		this.code = code;
		this.message=code.getErrorMessage();
	}

	public Result() {
		this.code = Code.SUCCESS;
		this.message = "成功";
	}

	public Result(Code code, String message) {
		this.code = code;
		this.message = message;
	}

	public Result(Code code, String message, Object data) {
		this.code = code;
		this.message = message;
		this.data = data;
	}

	public void setMessage(Code code, String message) {
		this.code = code;
		this.message = message;
	}

	public void setMessage(Code code, String message, Object data) {
		this.code = code;
		this.message = message;
		this.data = data;
	}
}
